.( ;Output of bytecode_compiler.f )

(
: sub  dup drop ;
: hi   # $2000 vp! # 1 # 1 + v! sub ;
entry wat  # 1 @ if # 2 if # 3 then then b: PAD_STATE end
)

label frames
dw ms_player_idle_right
dw ms_player_idle_left
dw ms_player_idle_fwd
dw ms_player_idle_back
dw ms_player_jog_right_0 \ 4
dw ms_player_jog_right_1 \ 5
dw ms_player_jog_left_0  \ 6
dw ms_player_jog_left_1  \ 7
dw ms_player_jog_fwd_0   \ 8
dw ms_player_jog_fwd_1   \ 9
dw ms_player_jog_back_0  \ 10
dw ms_player_jog_back_1  \ 11
dw ms_player_pickup_fwd


\ optimization ideas
\   drop literal
\   literal literal
\   literal and

\   literal fetch      \
\   literal ffetch     \
\   literal store      \_ explicit words (like !:) supporting index register?
\   literal plusstore  /

\   # 0 
\   # 1 literal +!

: framebase
	b: PAD_STATE @
		dup b: PAD_UP and if drop # 10 # 10   # 0 # $e8 exit then
		dup b: PAD_DOWN and if drop # 8 # 10  # 0 # $18 exit then
		dup b: PAD_LEFT and if drop # 6 # 6   # $e8 # 0 exit then
		b: PAD_RIGHT and if # 4 # 6           # $18 # 0 exit then
		# 0 # 255 over dup ;

: playersprite  ( frame speed -- d:addr )
	a: frames

	\ animation primitive candidate
	# 1 b: PLAYER_CNT +!
	b: PLAYER_CNT @ < if
		# 0 b: PLAYER_CNT !
		# 1 b: PLAYER_ACNT +!
	then
	b: PLAYER_ACNT @ # 1 and + 2* +a @+ @+
	;

: drawplayer
 	b: PLAYER_X f@ b: PLAYER_Y f@ framebase
	b: PLAYER_Y f+! b: PLAYER_X f+!
	playersprite

	# $be a: PPU_MASK !+
	metaspr
	;

\ 	# 0 b: FRAMECNT @ # 20 # 0 dup playersprite metaspr ;

entry script

	\ draw sprites
	# 0        \ OAM offset
	\ here would be where to put priority-quirk sprites
	\ draw the player
	drawplayer
	end

